//  总部数量单
function quantityDocuments(data) {
	// 单据时间
	var time = data.orderTime.substring(0, 10);
	// 经手人
	var auditorName = data.auditorName;
	// 客户名称
	var clientName = data.clientName;
	//单据类型
	var orderType = "";
	if(data.orderNumType ==0){
		orderType = "销售数量单";
	}else if(data.orderNumType ==1){
		orderType = "销售退货单";
	}else{
		orderType = "销售赠送单";
	}
	// 库房
	var storeName = data.storeName;
	// 取循环次数(打印页数）
	var counts = parseInt(data.products.length / 18);
	// 取余数
	var end = data.products.length % 18;
	// 单据总页数
	var pageNum = "";
	// 最后一页是否满18条
	if (end != 0) {
		pageNum = parseInt(counts) + 1;
		counts = counts + 1;
	} else {
		pageNum = parseInt(counts);
	}

	for (i = 1; i <= counts; i++) {

		if (i == counts + 1) {
			var endInfo = "";
			var sum = 0;

			var infoEnd = data.products.slice(counts * 19, counts * 19 + end);
			for (y = 0; y < infoEnd.length; y++) {

				endInfo += "<tr><td>" + infoEnd[y].year + infoEnd[y].brand
						+ info[y].quarter + "</td><td>"
						+ infoEnd[y].productCode + infoEnd[y].color
						+ "</td><td>" + infoEnd[y].category + "</td><td>"
						+ infoEnd[y].unit + "</td><td>" + infoEnd[y].quantity
						+ "</td></tr>\n +"
				sum += parseInt(infoEnd[y].quantity);
				// 最后一行算合计
				if (y == infoEnd.length - 1) {
					endInfo += "<tr><td>合计</td>  <td></td><td></td><td></td><td>"+ sum + "</td></tr>\n +"
				}
			}
			//quantityPrint(pageNum,i, orderType,storeName,time, auditorName, clientName,endInfo);
			console.log(endInfo);

		} else {
			var info = "";
			var sum = 0;

			var infoTwo = data.products.slice((i - 1) * 18, (i - 1) * 18 + 18);
			for (z = 0; z < infoTwo.length; z++) {
				info += "<tr><td>" + infoTwo[z].year + infoTwo[z].brand
						+ infoTwo[z].quarter + "</td><td>"
						+ infoTwo[z].productCode + infoTwo[z].color
						+ "</td><td>" + infoTwo[z].category + "</td><td>"
						+ infoTwo[z].unit + "</td><td>" + infoTwo[z].quantity
						+ "</td></tr>\n +"
				sum += parseInt(infoTwo[z].quantity);
				// 最后一行算合计
				if (z == infoTwo.length - 1) {

					info += "<tr><td>合计</td>  <td></td><td></td><td></td><td>"
							+ sum + "</td></tr>\n +"
				}
			}

			//quantityPrint(pageNum,i, orderType,storeName, time, auditorName, clientName, info);
			console.log(info);
		}
	}

}

// 数量单据打印输出方法
function quantityPrint(pageNum, page,  orderType,storeName,time, auditorName, clientName, data) {

	LODOP.PRINT_INITA(5, 1, 1183, 600, "千禧总部——销售数量单小票打印");
	LODOP.SET_PRINT_PAGESIZE(1, 2100, 1400, "");
	LODOP.ADD_PRINT_TEXT(1, 300, 791, 25,
			"                                                      共" + pageNum
					+ "页     第" + page + "页      ");
	LODOP.ADD_PRINT_TEXT(15, 5, 846, 35,
			"     千禧宝贝儿童服饰连锁 ("+orderType+") (www.qxbaby.com)");
	LODOP.SET_PRINT_STYLEA(0, "FontSize", 18);
	LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
	LODOP.ADD_PRINT_TEXT(46,7,842,20,"      日期： "+time+"        经手人：   "+auditorName+"           客户名称:    "+clientName+"             库房：" + storeName);
	LODOP.ADD_PRINT_LINE(63, 75, 63, 170, 0, 0);
	LODOP.ADD_PRINT_LINE(63, 220, 63, 330, 0, 0);
	LODOP.ADD_PRINT_LINE(63, 410, 63, 530, 0, 0);
	LODOP.ADD_PRINT_LINE(63, 580, 63, 720, 0, 0);
	LODOP.ADD_PRINT_TABLE(69,15,824,405,"<style> table,td,th {border: 1px solid black; border-style: solid;border-collapse: collapse;font-size:13px;}  td{text-align:center;}</style>\n"
							+ "<table border='1'  width='700px'><tr><td style='width:300px;'>商品名称</td><td style='width:220px'>商品型号</td><td style='width:300px'>商品类型</td><td style='width:150px'>单位</td><td style='width:150px'>数量</td></tr>\n"
							+ data +

							"</table>");

	LODOP.ADD_PRINT_TEXT(452,6,841,20,"    地址： 成都市荷花池大成市场二期A座6楼6号（总部）            电话： 028-83368588/83367588 （总部）       ");
	//打印预览方法
	//LODOP.PREVIEW();
	//打印设计
	//LODOP.PRINT_DESIGN();
	//直接打印（有水印）
	//LODOP.PRINT();
}

// 总部销售价格单
function priceDocuments(data) {
	// 单据时间
	var time = data.orderTime.substring(0, 10);
	// 经手人
	var auditorName = data.auditorName;
	// 客户名称
	var clientName = data.clientName;
	// 客户地区
	var clientArea = data.clientArea;
	//单据类型
	var orderType = "";
	if(data.orderNumType ==0){
		orderType = "销售单";
	}else if(data.orderNumType ==1){
		orderType = "退货单";
	}else{
		orderType = "赠送单";
	}
	// 库房
	var storeName = data.storeName;
	// 取循环次数(打印页数）
	var counts = parseInt(data.products.length / 15);
	// 取余数
	var end = data.products.length % 15;
	// 单据总页数
	var pageNum = parseInt(counts) + 1;
	// 合计数量
	var amountTo = data.totalQ;
	// 合计金额
	var totalAmount = data.totalWholeSales;
	// 上欠
	var preAcctAmt = data.preAcctAmt;
	// 现金
	var cash = data.cash;
	// 优惠
	var totalDiscount = 0;
	// 下欠
	var postAcctAmt = data.postAcctAmt;

	for (i = 1; i <= pageNum; i++) {

		if (i == pageNum) {
			
			//没有余数,并且是最后一页,则总计单起一页
			if(end == 0  && i == pageNum ){
				var sum = "";
				sum += "<tr><td>总合计</td><td></td><td></td><td></td><td>"+amountTo+"</td><td></td><td></td><td></td><td>"+totalAmount+"</td></tr>\n";
				//pricePrint(pageNum,i,orderType,clientArea,storeName, time, auditorName, clientName,sum,preAcctAmt,cash,totalDiscount,postAcctAmt);
				//console.log(sum);
			}else {
				var endInfo = "";
				var sumNumber = 0;
				var sum = 0;
				var infoEnd = data.products.slice(counts * 15, counts * 15 + end);
				for (y = 0; y < infoEnd.length; y++) {

					endInfo += "<tr><td>" + infoEnd[y].year + infoEnd[y].brand
							+ infoEnd[y].quarter + "</td><td>"
							+ infoEnd[y].productCode + infoEnd[y].color
							+ "</td><td>" + infoEnd[y].category + "</td><td>"
							+ infoEnd[y].unit + "</td><td>" + infoEnd[y].quantity
							+ "</td><td>" + infoEnd[y].selectPrice
							+ "</td><td>" + infoEnd[y].discountRate
							+ "</td><td>" + infoEnd[y].wholeSales
							+ "</td><td>" + infoEnd[y].totalWholeSales
							+ "</td></tr>\n" 
					sumNumber += parseInt(infoEnd[y].quantity);
					sum += parseInt(infoEnd[y].totalWholeSales);
					// 最后一行算合计
					if (y == infoEnd.length - 1) {
						endInfo += "<tr><td>页小计</td><td></td><td></td><td></td><td>" + sumNumber +"</td><td></td><td></td><td></td><td>"+ sum + "</td></tr>\n" +
								"<tr><td>总合计</td><td></td><td></td><td></td><td>"+amountTo+"</td><td></td><td></td><td></td><td>"+totalAmount+"</td></tr>\n" 		
					}
				}
				//pricePrint(pageNum,i,orderType,clientArea,storeName, time, auditorName, clientName,endInfo,preAcctAmt,cash,totalDiscount,postAcctAmt);
				//console.log(endInfo);
			}
			
		} else {
			var info = "";
			var sumNumber = 0;
			var sum = 0;

			var infoTwo = data.products.slice((i - 1) * 15, (i - 1) * 15 + 15);
			for (z = 0; z < infoTwo.length; z++) {
				info += "<tr><td>" + infoTwo[z].year + infoTwo[z].brand
						+ infoTwo[z].quarter + "</td><td>"
						+ infoTwo[z].productCode + infoTwo[z].color
						+ "</td><td>" + infoTwo[z].category + "</td><td>"
						+ infoTwo[z].unit + "</td><td>" + infoTwo[z].quantity
						+ "</td><td>" + infoTwo[z].selectPrice
						+ "</td><td>" + infoTwo[z].discountRate
						+ "</td><td>" + infoTwo[z].wholeSales
						+ "</td><td>" + infoTwo[z].totalWholeSales
						+ "</td></tr>\n + "
				sumNumber += parseInt(infoTwo[z].quantity);
				sum += parseInt(infoTwo[z].totalWholeSales);
				// 最后一行算合计
				if (z == infoTwo.length - 1) {

					info += "<tr><td>页小计</td><td></td><td></td><td></td><td>" + sumNumber +"</td><td></td><td></td><td></td><td>"
							+ sum + "</td></tr>\n +"
				}
			}
			//pricePrint(pageNum,i,orderType,clientArea,storeName, time, auditorName, clientName,info,preAcctAmt,cash,totalDiscount,postAcctAmt);
			//console.log(info);
			
		}
	}

}

// 价格单据打印输出方法
function pricePrint(pageNum, page,orderType,clientArea,storeName, time, auditorName, clientName, data,preAcctAmt,cash,totalDiscount,postAcctAmt) {

	LODOP.PRINT_INITA(5,1,1183,600,"千禧总部——销售价格单小票打印");
	LODOP.SET_PRINT_PAGESIZE(1,2100,1400,"");
	LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE",1);
	LODOP.ADD_PRINT_TEXT(4,114,100,33,orderType);
	LODOP.SET_PRINT_STYLEA(0,"FontSize",19);
	LODOP.SET_PRINT_STYLEA(0,"Bold",1);
	LODOP.ADD_PRINT_TEXT(9,225,408,27," 千禧宝贝品牌儿童服饰连锁(www.qxbaby.com)");
	LODOP.SET_PRINT_STYLEA(0,"FontSize",13);
	LODOP.SET_PRINT_STYLEA(0,"Bold",1);
	LODOP.ADD_PRINT_TEXT(11,648,116,23,"共"+pageNum+"页 -  第"+page+"页      ");
	LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
	LODOP.ADD_PRINT_TEXT(37,5,758,25,"      日期： "+time+"        经手人：   "+auditorName+"           客户名称:      "+clientName+"             地区：     "+clientArea);
	LODOP.ADD_PRINT_LINE(55, 75, 55, 170, 0, 0);
	LODOP.ADD_PRINT_LINE(55, 220, 55, 320, 0, 0);
	LODOP.ADD_PRINT_LINE(55, 410, 55, 530, 0, 0);
	LODOP.ADD_PRINT_LINE(55, 580, 55, 720, 0, 0);
	LODOP.ADD_PRINT_TABLE(61,1,824,405,"<style> table,td,th {border: 1px solid black; border-style: solid;border-collapse: collapse;font-size:13px;}  td{text-align:center;}</style>\n"
							+ "<table border='1'  width='760px'><tr><td style='width:130px;'>商品名称</td><td style='width:70px'>商品型号</td><td style='width:110px'>商品类型</td><td style='width:40px'>单位</td><td style='width:30px'>数量</td><td style='width:40px'>单价</td><td style='width:30px'>折扣</td><td style='width:50px'>折后价</td><td style='width:60px'>折后金额</td></tr>\n"
							+ data
							+ "</table>");

	LODOP.ADD_PRINT_TEXT(417,8,323,20,"   地址： 成都市荷花池大成市场二期A座6楼6号（总部） ");
	LODOP.ADD_PRINT_TEXT(436,8,277,20,"   电话： 028-83368588/83367588 （总部）");
	LODOP.ADD_PRINT_TEXT(421,428,341,20,"换货需齐码，包装齐全；且当季，否则不予退换");
	LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
	LODOP.SET_PRINT_STYLEA(0,"Bold",1);
	LODOP.ADD_PRINT_TEXT(373,56,69,20,"上欠金额：                               ");
	LODOP.ADD_PRINT_TEXT(396,57,52,20,"优惠：                                       ");
	LODOP.ADD_PRINT_TEXT(374,117,100,20,preAcctAmt); //上欠
	LODOP.ADD_PRINT_TEXT(372,321,75,20,"现收金额：");
	LODOP.ADD_PRINT_TEXT(394,320,75,20,"总欠金额:");
	LODOP.ADD_PRINT_TEXT(372,414,100,20,cash); //现金
	LODOP.ADD_PRINT_TEXT(396,124,100,20,totalDiscount); // 优惠
	LODOP.ADD_PRINT_TEXT(394,400,100,20,postAcctAmt); // 总欠金额
	LODOP.ADD_PRINT_LINE(387, 105, 387, 190, 0, 0);
	LODOP.ADD_PRINT_LINE(385, 380, 385, 480, 0, 0);
	LODOP.ADD_PRINT_LINE(410, 95, 410, 190, 0, 0);
	LODOP.ADD_PRINT_LINE(408, 380, 408, 480, 0, 0);
	LODOP.ADD_PRINT_TEXT(373,551,55,20,"库房：");
	LODOP.ADD_PRINT_TEXT(372,606,100,20,storeName);
	LODOP.ADD_PRINT_LINE(386, 585, 386, 670, 0, 0);

	//打印预览
	//LODOP.PREVIEW();
	//打印设计
	//LODOP.PRINT_DESIGN();
	//直接打印（有水印）
	//LODOP.PRINT();
}
